'use strict';

let nunjucks = require('nunjucks');

function createEnv(path,opts){
    path = path || '';
    opts = opts || {};
    let optsEnv = {
        aotuescape: opts.aotuescape || true,
        trimBlocks : opts.trimBlock || false,
        IstripBlocks : opts.IstripBlocks || false,
        noCache:opts.noCache || true ,
        watch : opts.watch || true
    }
    let env = nunjucks.configure(path,optsEnv);
    return env;
}

module.exports=async(ctx,next)=>{
    let env = createEnv();
    ctx.render = function(views,module){
        ctx.body = env.render(views,module);
    }
    await next();
}